/*****************************************************************
 * 设备上传升级文件，和升级是另外一台单独的服务器
 ****************************************************************/

import request from '@/plugin/axios'

export function getCollectorList(pageno, pagesize,formdata){
    var data = {};
    data.pageno = pageno;
    data.pagesize = pagesize;
    if (formdata) {
        data = Object.assign(formdata, data);
    }
    return request({
        url: '/Collector/List',
        method: 'post',
        data
    });
    
    
}

export function getUpgradeFiles(){
    return request({
        url: '/Common/getUpgradeFileList',
        method: 'post',
        data:{}
    });
}

/**
 * 上传升级文件
 * @param {*} file 
 */
export function uploadFile(file){
    
    //上传文件，后端要求必须为formData类型
    let fmData = new FormData();
    fmData.append("img",file);
    fmData.append("localName",file.name);
    fmData.append("UserId",1);

    return request({
        url: 'http://112.74.169.129:9001/upgrade/uploadImg',
        method: 'post',
        //data:{img:file,localName:file.name,UserId:1},
        data:fmData,
        headers:{
            "Content-Type":"multipart/form-data"
        }
    });
}

/**
 * 升级
 * @param {*} rtuSN 
 * @param {*} fileName 
 * @param {*} forceUpdate 
 * @param {*} closeLastUpdate 
 */
export function upgradeSubmit(rtuSN,fileName, forceUpdate = false, closeLastUpdate = false){
    return request({
        url: 'http://112.74.169.129:9001/upgrade/UpgradeInvByFileName',
        method: 'post',
        data:{
            RtuSN:rtuSN,
            fileName:fileName,
            forceUpdate:forceUpdate,
            closeLastUpdate:closeLastUpdate
        }
    });

}